package com.wzy.ssm.score.controller;

import com.wzy.ssm.score.model.ScoreList;
import com.wzy.ssm.score.model.ScoreListExample;
import com.wzy.ssm.score.service.ScoreListService;
import com.wzy.ssm.util.IdUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//添加注解
@Controller
public class ScoreListController {

    private ScoreListService scoreListService;

    //通过构�?�器注入service
    public ScoreListController(ScoreListService scoreListService){
        this.scoreListService=scoreListService;
    }

    //查询数据
    @GetMapping("/scoreList")
    @ResponseBody
    public List<ScoreList> selectScoreList(){
        //1 构�?�查询条�?
        //1.1 创建查询条件�?
        ScoreListExample example = new ScoreListExample();
        //1.2 创建条件构�?�器
        ScoreListExample.Criteria criteria = example.createCriteria();
        //1.3 通过criteria设置条件
        //...

        //2 根据条件查询
        List<ScoreList> list = scoreListService.selectByExample(example);

        return list;
    }
    //添加数据
    @PostMapping("/scoreList")
    @ResponseBody
    public ScoreList insertUser(@RequestBody ScoreList scoreList){
        //准备数据
        //...
        Integer id = IdUtil.nextId9();
        scoreList.setId(id);
        scoreListService.insertSelective(scoreList);

        return scoreList;
    }
    //修改数据
    @PutMapping("/scoreList")
    @ResponseBody
    public ScoreList updateUser(@RequestBody ScoreList scoreList){
        //准备数据
        //...

        scoreListService.updateByPrimaryKeySelective(scoreList);
        //只返回修改的字段数据
        return scoreList;
        //或�??,通过主键,从数据库查询完整的数�?,然后返回
        //return scoreListService.selectByPrimaryKey(scoreList.getScoreListId);

    }
    //删除数据
    @DeleteMapping("/scoreList/{id}")
    @ResponseBody
    public String delUser(@PathVariable("id") Integer scoreListId){

        scoreListService.deleteByPrimaryKey(scoreListId);

        //返回状�?�码
        return "200";
    }
}
